/**
 * 
 */
package com.sidom.movieIndexer.domain.file;

import java.util.Comparator;
import java.util.List;

import org.apache.commons.lang.builder.CompareToBuilder;

import com.sidom.movieIndexer.domain.Movie;
import com.sidom.movieIndexer.util.CollectionUtils;

/**
 * {@link Comparator} used by {@link CollectionUtils} to sort the {@link List} of {@link Movie}s on {@link MovieFile#getCleanedFileName()}
 * @author Siebe
 */
public class MovieFileCleanedFileNameComparator implements Comparator<Movie>{
	@Override
	public int compare(Movie movie1, Movie movie2) {
		if(movie1==null && movie2==null){
			return 0;
		}
		if(movie1==null && movie2!=null){
			return -1;
		}
		if(movie2==null && movie1!=null){
			return +1;
		}
		if(movie1.getMovieFile()==null && movie2.getMovieFile()==null){
			return 0;
		}
		if(movie1.getMovieFile()==null && movie2.getMovieFile()!=null){
			return -1;
		}
		if(movie2.getMovieFile()==null && movie1.getMovieFile()!=null){
			return +1;
		}
		return new CompareToBuilder().append(
				movie1.getMovieFile().getCleanedFileName(),
				movie2.getMovieFile().getCleanedFileName())
				.toComparison();
	}
}
